package NC;

//没有ac
public class NC40 {
    public static ListNode addInList (ListNode head1, ListNode head2) {
        // write code here
        long a=0,b=0;
        while (head1!=null){
            a = a*10 + head1.val;
            head1 = head1.next;
        }
        while (head2!=null){
            b = b*10 + head2.val;
            head2 = head2.next;
        }
        long ans = a+b;
        ListNode root = new ListNode(0);
        while (ans!=0){
            long temp = ans %10 ;
            ListNode t = new ListNode((int) temp);
            t.next = root.next;
            root.next=  t;
            ans/=10;
        }
        return root.next;
    }

    public static void main(String[] args) {
        ListNode a1 = new ListNode(9);
        ListNode a2 = new ListNode(3);
        ListNode a3 = new ListNode(7);
        a1.next = a2;
        a2.next = a3;
        ListNode b1 = new ListNode(6);
        ListNode b2 = new ListNode(3);
        b1.next = b2;
        ListNode ans = addInList(a1,b1);

    }
}